# Importing Data
SPAIN <- read_excel("C:/users/Biniam/Desktop/Documents/Academic/Thesis/Analysis Folder/Excel Files/Steel/TSA.xlsx",sheet = "Sheet1", range = "AF1:AF239")

# Checking the Imported Data
View(SPAIN)
# Creating Time Series Data
SPAIN_ts <- ts(SPAIN, start=c(2000,1), end=c(2019,09), frequency=12)
# Viewing and Checking the Created Time Series Data
SPAIN_ts
sum(is.na(SPAIN_ts))
library(forecast)
SPAIN_ts <- tsclean(SPAIN_ts)
SPAIN_ts

# Identification: Plotting the Time Series Data
plot(SPAIN_ts)

# Estimating the appropriate model
SPAIN_ts_model <- auto.arima(SPAIN_ts)
SPAIN_ts_model

# Forecasting
options(max.print=1000000)
SPAIN_ts_forecast <- forecast (SPAIN_ts_model, level=c(95), h=255)
plot(SPAIN_ts_forecast)
SPAIN_ts_forecast             

# Exporting
write.table(SPAIN_ts_forecast, file="/users/Biniam/Desktop/Documents/Academic/Thesis/Result Folder/TSA Results/Excel Files/From R/Steel/SPAIN_TSA.csv", sep=",")
